<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from 'echarts';
require('echarts/theme/macarons2') // echarts theme
import resize from './mixins/resize'
import { listTargetSalary } from '@/api/system/resumeStatistics.js'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    },
  },
  data() {
    return {
      chart: null,
      lineYValue: [],
      lineXValue: [],
    }
  },
  mounted() {
    this.$nextTick(() => {
      listTargetSalary().then(res => {
        this.lineXValue = res.data.name
        this.lineYValue = res.data.value
        this.initChart()
      })
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons2')
      this.setOptions()
    },
    setOptions() {
      this.chart.setOption({
        title: {
          text: "薪酬统计",
          x: "center",
          textStyle: {
            color: "#595959",
            fontSize: 22,
          },
        },
        xAxis: {
          data: this.lineXValue,
          boundaryGap: false,
          axisTick: {
            show: false
          },
          axisLabel: {
            interval: 0,
            rotate: 45,
            show: true
          }
        },
        grid: {
          left: 10,
          right: 10,
          bottom: 20,
          top: 50,
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          },
          padding: [5, 10]
        },
        yAxis: {
          axisTick: {
            show: false
          }
        },
        series: [{
          name: '薪酬', itemStyle: {
            normal: {
              color: '#FF005A',
              lineStyle: {
                color: '#FF005A',
                width: 2
              }
            }
          },
          smooth: true,
          type: 'line',
          data: this.lineYValue,
          animationDuration: 2800,
          animationEasing: 'cubicInOut'
        },
        ]
      })
    }
  }
}
</script>
